home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 15 / BBS in a box XV-1.iso / Files / Internet / Misc / Uupc 3.1 sources.sit / uupc 3.1 sources Folder / Mac specific / Unix lib / splitname.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-01  |  638 b   |  46 lines  |  [TEXT/PEDT]

  1.  
  2. #include "splitname.proto.h"
  3.  
  4.  
  5. /* splitname
  6.  
  7.         split and and copy directory and filename from 
  8.         pathname to dir and name
  9. */
  10. splitname(char *path, char *dir, char *name)
  11. {
  12.     register char *cp;
  13.     register int i;
  14.  
  15.     strcpy( dir, path );
  16.     i = strlen( dir);
  17.     cp = dir + i;
  18.  
  19.  
  20.     while ((i-- > 0) && (*--cp != '/') && (*cp != ':') );
  21.  
  22.     if (*cp == '/') cp++;
  23.     else if (*cp == ':') cp++;
  24.     
  25.     strcpy( name, cp );
  26.     *cp = '\0';
  27.  
  28. }
  29.  
  30. #ifdef TEST
  31. #include <stdio.h>
  32.  
  33. main (void)
  34.  
  35. {
  36.     char buf[100];
  37.     char dir[100], name[100];
  38.  
  39.     while (gets( buf ) != NULL ) {
  40.         splitname( buf, dir, name );
  41.         printf( "%s -> \"%s\"   \"%s\"\n", buf, dir, name );
  42.     }
  43. }
  44.  
  45. #endif
  46.